package com.golxen.framework.netty.session.base;


import com.golxen.framework.PBPacket.PBPacket;
import com.golxen.framework.common.server.eServerType;
import com.golxen.utils.LogUtil;
import io.netty.channel.Channel;

import java.net.InetSocketAddress;

public class ServerLinkedGroup extends AbstractSessionGroup<NettyChannelSession> {

	protected long serverId;
	protected int serverIndex;
	protected int port;
	protected String address;
	protected eServerType serverType;
	protected boolean isActive;

	public ServerLinkedGroup(int size) {
		super(size);
	}

	public ServerLinkedGroup(int size, int serverIndex) {
		super(size);
		this.serverIndex = serverIndex;
	}

	public ServerLinkedGroup(int size, int serverIndex, int port, String address, eServerType serverType) {
		super(size);
		this.serverIndex = serverIndex;
		this.port = port;
		this.serverType = serverType;
		this.isActive = false;
		this.address = address;
	}

	public long getServerId() {
		return serverId;
	}

	public void setServerId(long serverId) {
		this.serverId = serverId;
	}

	public int getServerIndex() {
		return serverIndex;
	}

	public int getPort() {
		return port;
	}

	public String getAddress() {
		return address;
	}


	public boolean isActive() {
		return isActive;
	}

	public void setActive(boolean isActive) {
		this.isActive = isActive;
	}

	public eServerType getServerType() {
		return serverType;
	}

	protected NettyChannelSession createSession(Channel channel, int index, InetSocketAddress addr) {
		return null;
	}

	public void addSession(AbstractSession socketSession, int index) {
		if (index >= sessions.length) {
			LogUtil.COMMON.error("index out of rang session[] , length : " + sessions.length + " , index : " + index);
			return;
		}

		sessions[index] = socketSession;
		LogUtil.COMMON.info("add link i = " + index);
	}

	public NettyChannelSession selectSocketSession() {
		return get(0);
	}

	public void sendPacket(long userId, PBPacket packet) {
		write(userId, packet);
	}

	public void send(PBPacket packet) {
		write(packet.getPlayerId(), packet);
	}


	@Override
	protected NettyChannelSession connect(int index) throws Exception {
		return null;
	}


}
